home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / tool chest / development kits / hypercard related / xcmds & xfcns / alias xfcn 1.3 / source / trap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-13  |  1.9 KB  |  96 lines

  1. /*
  2.     trap.c
  3.     Functions to support testing for traps
  4.     and testing for Gestalt features.
  5.     
  6.     11-13-90 1.0d3 JRP    original
  7.     08-Apr-93 1.2d1    JRP    correct error in aliasAvailable Gestalt parameter,
  8.                         was causing write-to-nil.
  9. */
  10.  
  11. #include    <Types.h>
  12. #include    <Traps.h>
  13. #include    <OSUtils.h>
  14. #include    <GestaltEqu.h>
  15.  
  16. #include    "trap.pro"
  17.  
  18. short aliasAvailable(void)
  19. /*
  20.     Returns true if Alias is available.
  21. */
  22. {
  23.     long    response;
  24.     short    result=false;
  25.  
  26.     if(gestaltAvailable())
  27.     {
  28.         if(Gestalt(gestaltAliasMgrAttr, &response)==noErr)
  29.         {
  30.                 // See if the gestaltAliasMgrPresent-th bit is set.
  31.             result = response & (1 << gestaltAliasMgrPresent);
  32.         }
  33.     }
  34.     return result;
  35. }    /*    --------------------------------------------    aliasAvailable        */
  36.  
  37. short gestaltAvailable(void)
  38. /*
  39.     Returns true if gestalt is available.
  40.     From IM-VI. chap 3, page 8
  41. */
  42. {
  43.     #define    _Gestalt    0xA1AD
  44.     
  45.     return(trapAvailable(_Gestalt));
  46. }    /*    --------------------------------------------    gestaltAvailable        */
  47.  
  48. short getTrapType(theTrap)
  49. /*
  50.     Returns the trap type.
  51.     From IM-VI. chap 3, page 8
  52. */
  53.     short    theTrap;
  54. {
  55.     #define    trapMask    0x0800
  56.     
  57.     if(theTrap & trapMask)
  58.         return ToolTrap;
  59.     else
  60.         return OSTrap;
  61. }    /*    --------------------------------------------    getTrapType        */
  62.  
  63. short numToolboxTraps(void)
  64. /*
  65.     Returns the number of toolbox traps.
  66.     From IM-VI. chap 3, page 8
  67. */
  68. {
  69.     if(NGetTrapAddress(_InitGraf, ToolTrap)==
  70.             NGetTrapAddress(0xAA6E, ToolTrap))
  71.                 return 0x200;
  72.     else
  73.         return 0x400;
  74. }    /*    --------------------------------------------    numToolboxTraps        */
  75.  
  76. short trapAvailable(theTrap)
  77. /*
  78.     Returns true if the trap is available.
  79.     From IM-VI. chap 3, page 8
  80. */
  81.     short    theTrap;
  82. {
  83.     short    tType;
  84.  
  85.     tType = getTrapType(theTrap);
  86.     if(tType==ToolTrap)
  87.     {
  88.         theTrap = theTrap & 0x07FF;
  89.         if(theTrap>=numToolboxTraps())
  90.             theTrap = _Unimplemented;
  91.     }
  92.     return(NGetTrapAddress(theTrap, tType)!=
  93.                 NGetTrapAddress(_Unimplemented, ToolTrap));
  94. }    /*    --------------------------------------------    trapAvailable    */
  95.  
  96.